import xlsxwriter


workbook = xlsxwriter.Workbook('excel_demo.xlsx')
worksheet = workbook.add_worksheet('Sheet1')

# 设置第一列宽度
worksheet.set_column('A:A', len('hello')+1)

# 设置加粗
bold = workbook.add_format({'bold': True})
# A1写入纯文本
worksheet.write('A1', 'Hello')
# A2写入带格式文本
worksheet.write('A2', 'World', bold)

# 行 列 数字 ，下标从0开始
worksheet.write(2, 0, 123)
worksheet.write(3, 0, 123.456)

workbook.close()


def charts():
    workbook_chart = xlsxwriter.Workbook('chart_colunm.xlsx')
    worksheet_chart = workbook_chart.add_worksheet()
    # 定义字体
    bold_chart = workbook.add_format({'bold': 2})
    # 定义表头列
    headings = ['Number', 'Batch 1', 'Batch 2']
    data = [
        [2, 3, 4, 5, 6, 7],
        [10, 40, 50, 20, 10, 50],
        [30, 60, 70, 50, 40, 30]
    ]
    # 写入首行
    worksheet_chart.write_row('A1', headings, bold_chart)
    # 写入一列
    worksheet_chart.write_column('A2', data[0])
    worksheet_chart.write_column('B2', data[1])
    worksheet_chart.write_column('C2', data[2])

    workbook_chart.close()


if __name__ == '__main__':
    charts()
    print('Finished...')